/**
 * @description  : 证照-页签组件
 * @descriptionDetail : 证照-页签组件
 * @copyright    : 浙江烟草
 * @author       : dw
 * @create       : 2022-12-05 10:36:34
 */
<template>
    <view>
        <view class="retail">
            <!-- <fsection title="零售户信息" class="pl-16"></fsection> -->
            <theme-navbar :is-white="false" :title="navTitle" :custom-back="goBack" style="z-index: 99999"></theme-navbar>
            <u-gap :height="$theme.cm_section_top_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
        </view>
        <view class="rdcontent">
            <u-row gutter="16" align="top" class="divided-line">
                <u-col span="6">
                    <view class="msg-title">
                        许可证件
                    </view>
                    <view class="msg-context">
                        {{ basemsg.licNo || "/" }}
                    </view>
                </u-col>
                <u-col span="6">
                    <view class="msg-title">
                        老许可证件
                    </view>
                    <view class="msg-context">
                        {{ basemsg.oldLicNo || "/" }}
                    </view>
                </u-col>
            </u-row>
            <u-row gutter="16" align="top" class="divided-line">
                <u-col span="6">
                    <view class="msg-title">
                        持证人
                    </view>
                    <view class="msg-context">
                        {{ basemsg.managerName || "/" }}
                    </view>
                </u-col>
                <u-col span="6">
                    <view class="msg-title">
                        企业类型
                    </view>
                    <view class="msg-context">
                        {{ basemsg.ecoTypeName || "/" }}
                    </view>
                </u-col>
            </u-row>
            <u-row gutter="16" justify="space-between" align="top" class="divided-line">
                <u-col span="12">
                    <view class="msg-title">
                        企业名称（字号）
                    </view>
                    <view class="msg-context">
                        {{ basemsg.companyName || "/" }}
                    </view>
                </u-col>
            </u-row>
            <u-row gutter="16" justify="space-between" align="top" class="divided-line">
                <u-col span="12">
                    <view class="msg-title">
                        经营地址
                    </view>
                    <view class="msg-context">
                        {{ basemsg.businessAddr || "/" }}
                    </view>
                </u-col>
            </u-row>
            <u-row gutter="16" justify="space-between" align="top" class="divided-line">
                <u-col span="12">
                    <view class="msg-title">
                        统一社会信用代码
                    </view>
                    <view class="msg-context">
                        {{ basemsg.businessLicNo || "/" }}
                    </view>
                </u-col>
            </u-row>
            <u-row gutter="16" align="top" class="divided-line">
                <u-col span="10">
                    <view class="msg-title">
                        经纬度
                    </view>
                    <view class="msg-context lat">
                        {{ lnglat ? lnglat : '未采集' }}
                    </view>
                </u-col>
                <u-col span="2">
                    <view class="msg-title">
                        <view style="height: 18px;"></view>
                    </view>
                    <view class="msg-context" @click="gotoPoMapSearch">
                        <!-- 采集 -->
                        <image class="img-size" src="/static/market/new-location.png"></image>
                    </view>
                </u-col>
            </u-row>
            <view class="popup-submit-btns">
                <u-button class="u-btn" type="primary" @click="submitLngLat">提交</u-button>
            </view>
        </view>
    </view>
</template>

<script>
import fsection from "@/components/form-section.vue";
import certificateService from "@/service/certificate/certificate.service.js";

export default {
    components: {
        fsection,
    },
    onLoad(opt) {
        this.retailerUuid = opt.retailerUuid
        // this.farform = opt.from
        // let p = this.getRouteParam() || {};
        // this.marketGis = this.$u.deepClone(p);
        // if (this.marketGis) {
        //     console.log(this.marketGis, '已采集坐标----------------------')
        //     this.formData.latitude = this.marketGis.latitude;
        //     this.formData.longitude = this.marketGis.longitude;
        //     this.lnglatPo = [this.marketGis.longitude, this.marketGis.latitude].join(',')
        //     this.lnglat = this.lnglatPo
        // } else {
        //     this.marketGis = undefined;
        // }
        if (this.from == 1) {
            this.formData.ownAreaOrgUuid = opt.ownAreaOrgUuid || "";
            this.formData.ownAreaOrgName = opt.ownAreaOrgName || "";
            this.retailerPos = [opt.longitude, opt.latitude,];
            this.formData.relatveLic = true;
        }
    },
    data() {
        return {
            title: {
                basemsg: "零售户信息",
                // retailerUuid: this.retailerUuid
            },
            marketGis: undefined,
            retailerUuid: this.retailerUuid,
            basemsg: {},
            formData: {},
            specialTypeName: "",
            retailId: "",
            lnglat: null,
        }
    },
    created() {
        // this.marketGis={}
    },
    mounted() {
        this.loadcertificate()
    },
    methods: {
        loadcertificate() {
            let parms = {
                retailerUuid: this.retailerUuid,
                menuCode: null,
            }
            certificateService.getRetailcerCertificate(parms).then(res => {
                if (res.success) {
                    this.basemsg = res.bean.licenseInfoPre;
                    this.retailId = this.basemsg.retailerUuid.substring(23, 32)
                    if (res.bean.licenseInfoPre.longitude) {
                        this.lnglat = [this.basemsg.longitude, this.basemsg.latitude].join(',')
                    }
                    this.getSpecialType();
                }
            });
        },
        getSpecialType() {
            if (this.basemsg.specialType) {
                let tmp = [];
                this.specialType = this.basemsg.specialType.split(',');
                this.specialType.map((item) => {
                    tmp.push(this.$u.dic.getDicNameByKeyCode(this.$u.dic.DIC_KEYS.SPECIAL, item));
                });
                if (tmp.length > 0) {
                    this.specialTypeName = tmp.join(',');
                }
            } else {
                this.specialTypeName = '/';
            }
        },
        gotoPoMapSearch() {
            this.$u.route({
                url: 'pages/query/coordinateAcquisit/infoAndPoMap', type: 'to', params: {
                    retailerUuid: this.retailerUuid,
                }
            });
        },

        getPoMap() {

        },
        submitLngLat() {
            let that = this;
            if (!that.lnglat || that.lnglat == ',') {
                that.$u.toast('请采集坐标');
            } else {
                if (that.formData.longitude) {
                    that.basemsg.longitude = that.formData.longitude
                    that.basemsg.latitude = that.formData.latitude
                }
                certificateService
                    .saveOrUpdateRetailList({ ...that.basemsg, retailerUuid: that.retailerUuid })
                    .then((res) => {
                        if (res.success) {
                            // this.$u.success('采集成功', 200, () => {
                            //     that.backPrev({
                            //         paramKey: "params",
                            //         param: {},
                            //     });
                            // });
                            // // that.$u.toast('采集成功');
                            that.backPrev({
                                paramKey: "params",
                                param: {},
                            });

                        } else {
                            that.$u.toast('采集失败');
                        }
                    })
                    .catch((e) => {
                        that.$u.toast('调用失败');
                    });
            }
        },
        updateBackState(params) {
            console.log(params, this.formData)
            this.formData.latitude = params.params.latitude;
            this.formData.longitude = params.params.longitude;
            this.lnglat = [params.params.longitude, params.params.latitude].join(',')
            this.retailerUuid = params.params.retailerUuid
        }

    },

}
</script>

<style lang="scss" scoped>
@import "../../retailer/retailerInfo/retailerItem/retailItem.scss";

.img-size {
    width: 32rpx;
    height: 42rpx;
    vertical-align: middle;
}

.popup-submit-btns {
    width: calc(100% - 22px);
    position: fixed;
    bottom: 10rpx;
}
</style>
